package com.automation.fitness.core.userinfo;

import com.automation.common.MException;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 基础代谢
 * <p>
 * Basal Metabolic Rate
 */
@Getter
@AllArgsConstructor
public class BMR {
    private final double factor;

    public static BMR calculate(Gender gender, int age, double heightCm, double weightKg) {
        if (gender == Gender.MALE) {
            return new BMR(weightKg * 9.99 + heightCm * 6.25 - age * 4.92 + 5);
        } else if (gender == Gender.FEMALE) {
            return new BMR(weightKg * 9.99 + heightCm * 6.25 - age * 4.92 - 161);
        }
        throw new MException("暂不支持该性别");
    }

    @Override
    public String toString() {
        return String.format("BRM: %.2f", factor);
    }
}
